﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.Abstract;
using DataAccess.Repository;
using DataAccess.NHibernateHelper;
using Domain.Entity;
using log4net;

namespace Business.Service
{
    public class StaffServiceImpl : IStaffService
    {
        ILog log = LogManager.GetLogger("StaffServiceImpl");
        StaffRepository staffRepo;

        public StaffServiceImpl()
        {
            staffRepo = new StaffRepository(FluentNHibernateHelper.GetContext());
        }

        public IList<Staff> GetAllStaffs()
        {
            return staffRepo.List().Where(x => x.IsDeleted == false).ToList();
        }

        public void SaveStaff(Staff staff)
        {
            log.Debug("Save staff");
            staff.CreatedDate = DateTime.Now;
            staffRepo.Insert(staff);
            staffRepo.Commit();
        }

        public Staff GetStaffById(long id)
        {
            return staffRepo.List().Where(x => x.IsDeleted == false).ToList().Where(x=>x.ID == id).First();
        }

        public void UpdateStaff(Staff staff)
        {
            staffRepo.Update(staff);
            staffRepo.Commit();
        }

        public void DeleteStaff(Staff staff)
        {
            staffRepo.Delete(staff);
            staffRepo.Commit();
        }

        public IList<Staff> GetAllStaffs(string column, string value)
        {
            return staffRepo.GetAllStaffs(column, value);
        }

        public Staff GetStaffByEmail(string email)
        {
            return staffRepo.GetStaffByEmail(email);
        }
    }
}
